home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Technology Seed / Jan. '98 ATS.toast / QuickTime™ 3.0b11 / QTPublicInterfaces / CIncludes / fp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  29.6 KB  |  807 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        fp.h
  3.  
  4.      Contains:    FPCE Floating-Point Definitions and Declarations.
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    QuickTime 3.0 Beta
  8.  
  9.      Copyright:    © 1987-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FP__
  19. #define __FP__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24.  
  25. #if TARGET_OS_MAC
  26. #ifndef __MACTYPES__
  27. #include <MacTypes.h>
  28. #endif
  29. #endif
  30. /********************************************************************************
  31. *                                                                               *
  32. *    A collection of numerical functions designed to facilitate a wide          *
  33. *    range of numerical programming as required by C9X.                         *
  34. *                                                                               *
  35. *    The <fp.h> declares many functions in support of numerical programming.    *
  36. *    It provides a superset of <math.h> and <SANE.h> functions.  Some           *
  37. *    functionality previously found in <SANE.h> and not in the FPCE <fp.h>      *
  38. *    can be found in this <fp.h> under the heading "__NOEXTENSIONS__".          *
  39. *                                                                               *
  40. *    All of these functions are IEEE 754 aware and treat exceptions, NaNs,      *
  41. *    positive and negative zero and infinity consistent with the floating-      *
  42. *    point standard.                                                            *
  43. *                                                                               *
  44. ********************************************************************************/
  45.  
  46.  
  47.  
  48. #if PRAGMA_ONCE
  49. #pragma once
  50. #endif
  51.  
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55.  
  56. #if PRAGMA_IMPORT
  57. #pragma import on
  58. #endif
  59.  
  60. #if PRAGMA_STRUCT_ALIGN
  61.     #pragma options align=mac68k
  62. #elif PRAGMA_STRUCT_PACKPUSH
  63.     #pragma pack(push, 2)
  64. #elif PRAGMA_STRUCT_PACK
  65.     #pragma pack(2)
  66. #endif
  67.  
  68. /********************************************************************************
  69. *                                                                               *
  70. *                            Efficient types                                    *
  71. *                                                                               *
  72. *    float_t         Most efficient type at least as wide as float              *
  73. *    double_t        Most efficient type at least as wide as double             *
  74. *                                                                               *
  75. *      CPU            float_t(bits)                double_t(bits)               *
  76. *    --------        -----------------            -----------------             *
  77. *    PowerPC          float(32)                    double(64)                   *
  78. *    68K              long double(80/96)           long double(80/96)           *
  79. *    x86              long double(80)              long double(80)              *
  80. *                                                                               *
  81. ********************************************************************************/
  82. #if TARGET_CPU_PPC
  83. typedef float                             float_t;
  84. typedef double                             double_t;
  85. #elif TARGET_CPU_68K
  86. typedef long double                     float_t;
  87. typedef long double                     double_t;
  88. #elif TARGET_CPU_X86
  89. #if NeXT
  90. typedef double                             float_t;
  91. typedef double                             double_t;
  92. #else
  93. typedef long double                     float_t;
  94. typedef long double                     double_t;
  95. #endif  /* NeXT */
  96.  
  97. #elif TARGET_CPU_MIPS
  98. typedef double                             float_t;
  99. typedef double                             double_t;
  100. #elif TARGET_CPU_ALPHA
  101. typedef double                             float_t;
  102. typedef double                             double_t;
  103. #elif TARGET_CPU_SPARC
  104. typedef double                             float_t;
  105. typedef double                             double_t;
  106. #else
  107. #error unsupported CPU
  108. #endif  /* TARGET_CPU_SPARC */
  109.  
  110.  
  111. /********************************************************************************
  112. *                                                                               *
  113. *                              Define some constants.                           *
  114. *                                                                               *
  115. *    HUGE_VAL            IEEE 754 value of infinity.                            *
  116. *    INFINITY            IEEE 754 value of infinity.                            *
  117. *    NAN                 A generic NaN (Not A Number).                          *
  118. *    DECIMAL_DIG         Satisfies the constraint that the conversion from      *
  119. *                        double to decimal and back is the identity function.   *
  120. *                                                                               *
  121. ********************************************************************************/
  122.  
  123. #if TARGET_OS_UNIX
  124. #define        NAN                        sqrt(-1)
  125. #else
  126. #define      HUGE_VAL                  __inf()
  127. #define      INFINITY                  __inf()
  128. #define      NAN                       nan("255")
  129. #endif
  130.  
  131. #if TARGET_CPU_PPC
  132.     #define      DECIMAL_DIG              17 /* does not exist for double-double */
  133. #elif TARGET_CPU_68K
  134.     #define      DECIMAL_DIG              21
  135. #endif      
  136.  
  137. #if TARGET_OS_MAC
  138. /********************************************************************************
  139. *                                                                               *
  140. *                            Trigonometric functions                            *
  141. *                                                                               *
  142. *   acos        result is in [0,pi].                                            *
  143. *   asin        result is in [-pi/2,pi/2].                                      *
  144. *   atan        result is in [-pi/2,pi/2].                                      *
  145. *   atan2       Computes the arc tangent of y/x in [-pi,pi] using the sign of   *
  146. *               both arguments to determine the quadrant of the computed value. *
  147. *                                                                               *
  148. ********************************************************************************/
  149. EXTERN_API_C( double_t ) cos(double_t x);
  150.  
  151. EXTERN_API_C( double_t ) sin(double_t x);
  152.  
  153. EXTERN_API_C( double_t ) tan(double_t x);
  154.  
  155. EXTERN_API_C( double_t ) acos(double_t x);
  156.  
  157. EXTERN_API_C( double_t ) asin(double_t x);
  158.  
  159. EXTERN_API_C( double_t ) atan(double_t x);
  160.  
  161. EXTERN_API_C( double_t ) atan2(double_t y, double_t x);
  162.  
  163.  
  164.  
  165. /********************************************************************************
  166. *                                                                                *
  167. *                              Hyperbolic functions                             *
  168. *                                                                                *
  169. ********************************************************************************/
  170. EXTERN_API_C( double_t ) cosh(double_t x);
  171.  
  172. EXTERN_API_C( double_t ) sinh(double_t x);
  173.  
  174. EXTERN_API_C( double_t ) tanh(double_t x);
  175.  
  176. EXTERN_API_C( double_t ) acosh(double_t x);
  177.  
  178. EXTERN_API_C( double_t ) asinh(double_t x);
  179.  
  180. EXTERN_API_C( double_t ) atanh(double_t x);
  181.  
  182.  
  183.  
  184. /********************************************************************************
  185. *                                                                                *
  186. *                              Exponential functions                               *
  187. *                                                                                *
  188. *    expm1        expm1(x) = exp(x) - 1.  But, for small enough arguments,          *
  189. *                expm1(x) is expected to be more accurate than exp(x) - 1.        *
  190. *    frexp        Breaks a floating-point number into a normalized fraction       *
  191. *                and an integral power of 2.  It stores the integer in the       *
  192. *                object pointed by *exponent.                                    *
  193. *    ldexp        Multiplies a floating-point    number by an integer power of 2.    *
  194. *    log1p        log1p = log(1 + x). But, for small enough arguments,              *
  195. *                 log1p is expected to be more accurate than log(1 + x).          *
  196. *    logb        Extracts the exponent of its argument, as a signed integral        *
  197. *                  value. A subnormal argument is treated as though it were first    *
  198. *                  normalized. Thus:                                                *
  199. *                                     1   <=   x * 2^(-logb(x))   <   2             *
  200. *    modf        Returns fractional part of x as function result and returns     *
  201. *                integral part of x via iptr. Note C9X uses double not double_t.    *
  202. *    scalb        Computes x * 2^n efficently.  This is not normally done by        *
  203. *                  computing 2^n explicitly.                                         *
  204. *                                                                                *
  205. ********************************************************************************/
  206. EXTERN_API_C( double_t ) exp(double_t x);
  207.  
  208. EXTERN_API_C( double_t ) expm1(double_t x);
  209.  
  210. EXTERN_API_C( double_t ) exp2(double_t x);
  211.  
  212. EXTERN_API_C( double_t ) frexp(double_t x, int *exponent);
  213.  
  214. EXTERN_API_C( double_t ) ldexp(double_t x, int n);
  215.  
  216. EXTERN_API_C( double_t ) log(double_t x);
  217.  
  218. EXTERN_API_C( double_t ) log2(double_t x);
  219.  
  220. EXTERN_API_C( double_t ) log1p(double_t x);
  221.  
  222. EXTERN_API_C( double_t ) log10(double_t x);
  223.  
  224. EXTERN_API_C( double_t ) logb(double_t x);
  225.  
  226. EXTERN_API_C( long double ) modfl(long double x, long double *iptrl);
  227.  
  228. EXTERN_API_C( double_t ) modf(double_t x, double_t *iptr);
  229.  
  230. EXTERN_API_C( float ) modff(float x, float *iptrf);
  231.  
  232. EXTERN_API_C( double_t ) scalb(double_t x, long n);
  233.  
  234.  
  235.  
  236. /********************************************************************************
  237. *                                                                                *
  238. *                     Power and absolute value functions                          *
  239. *                                                                                *
  240. *    hypot        Computes the square root of the sum of the squares of its        *
  241. *                  arguments, without undue overflow or underflow.                 *
  242. *    pow            Returns x raised to the power of y.  Result is more accurate    *
  243. *                than using exp(log(x)*y).                                        *
  244. *                                                                                *
  245. ********************************************************************************/
  246. EXTERN_API_C( double_t ) fabs(double_t x);
  247.  
  248. EXTERN_API_C( double_t ) hypot(double_t x, double_t y);
  249.  
  250. EXTERN_API_C( double_t ) pow(double_t x, double_t y);
  251.  
  252. EXTERN_API_C( double_t ) sqrt(double_t x);
  253.  
  254.  
  255.  
  256. /********************************************************************************
  257. *                                                                                 *
  258. *                        Gamma and Error functions                               *
  259. *                                                                                 *
  260. *     erf            The error function.                                             *
  261. *     erfc        Complementary error function.                                      *
  262. *     gamma        The gamma function.                                                *
  263. *     lgamma        Computes the base-e logarithm of the absolute value of            *
  264. *                 gamma of its argument x, for x > 0.                                *
  265. *                                                                                 *
  266. ********************************************************************************/
  267. EXTERN_API_C( double_t ) erf(double_t x);
  268.  
  269. EXTERN_API_C( double_t ) erfc(double_t x);
  270.  
  271. EXTERN_API_C( double_t ) gamma(double_t x);
  272.  
  273. EXTERN_API_C( double_t ) lgamma(double_t x);
  274.  
  275.  
  276.  
  277. /********************************************************************************
  278. *                                                                                 *
  279. *                        Nearest integer functions                                 *
  280. *                                                                                 *
  281. *     rint        Rounds its argument to an integral value in floating point         *
  282. *                  format, honoring the current rounding direction.                   *
  283. *                                                                                 *
  284. *     nearbyint    Differs from rint only in that it does not raise the inexact    *
  285. *               exception. It is the nearbyint function recommended by the        *
  286. *                  IEEE floating-point standard 854.                                  *
  287. *                                                                                 *
  288. *     rinttol        Rounds its argument to the nearest long int using the current     *
  289. *                  rounding direction.  NOTE: if the rounded value is outside        *
  290. *                the range of long int, then the result is undefined.              *
  291. *                                                                                  *
  292. *     round        Rounds the argument to the nearest integral value in floating     *
  293. *                  point format similar to the Fortran "anint" function. That is:  *
  294. *                  add half to the magnitude and chop.                             *
  295. *                                                                                 *
  296. *     roundtol    Similar to the Fortran function nint or to the Pascal round.    *
  297. *                 NOTE: if the rounded value is outside the range of long int,    *
  298. *                  then the result is undefined.                                      *
  299. *                                                                                 *
  300. *     trunc        Computes the integral value, in floating format, nearest to        *
  301. *                 but no larger in magnitude than its argument.      NOTE: on 68K    *
  302. *                compilers when using -elems881, trunc must return an int        *
  303. *                                                                                 *
  304. ********************************************************************************/
  305. EXTERN_API_C( double_t ) ceil(double_t x);
  306.  
  307. EXTERN_API_C( double_t ) floor(double_t x);
  308.  
  309. EXTERN_API_C( double_t ) rint(double_t x);
  310.  
  311. EXTERN_API_C( double_t ) nearbyint(double_t x);
  312.  
  313. EXTERN_API_C( long ) rinttol(double_t x);
  314.  
  315. EXTERN_API_C( double_t ) round(double_t x);
  316.  
  317. EXTERN_API_C( long ) roundtol(double_t round);
  318.  
  319. #if TARGET_CPU_68K
  320. EXTERN_API_C( int ) trunc(double_t x);
  321.  
  322. #else
  323. EXTERN_API_C( double_t ) trunc(double_t x);
  324.  
  325. #endif  /* TARGET_CPU_68K */
  326.  
  327.  
  328. /********************************************************************************
  329. *                                                                                 *
  330. *                            Remainder functions                                   *
  331. *                                                                                 *
  332. *     remainder        IEEE 754 floating point standard for remainder.                *
  333. *     remquo            SANE remainder.  It stores into 'quotient' the 7 low-order    *
  334. *                    bits of the integer quotient x/y, such that:                *
  335. *                        -127 <= quotient <= 127.                                 *
  336. *                                                                                 *
  337. ********************************************************************************/
  338. EXTERN_API_C( double_t ) fmod(double_t x, double_t y);
  339.  
  340. EXTERN_API_C( double_t ) remainder(double_t x, double_t y);
  341.  
  342. EXTERN_API_C( double_t ) remquo(double_t x, double_t y, int *quo);
  343.  
  344.  
  345.  
  346. /********************************************************************************
  347. *                                                                                 *
  348. *                             Auxiliary functions                               *
  349. *                                                                                 *
  350. *     copysign        Produces a value with the magnitude of its first argument    *
  351. *                      and sign of its second argument.  NOTE: the order of the     *
  352. *                      arguments matches the recommendation of the IEEE 754         *
  353. *                    floating point standard,  which is opposite from the SANE    *
  354. *                    copysign function.                                             *
  355. *                                                                                 *
  356. *     nan                The call 'nan("n-char-sequence")' returns a quiet NaN         *
  357. *                      with content indicated through tagp in the selected         *
  358. *                    data type format.                                              *
  359. *                                                                                *
  360. *     nextafter        Computes the next representable value after 'x' in the         *
  361. *                    direction of 'y'.  if x == y, then y is returned.            *
  362. *                                                                                 *
  363. ********************************************************************************/
  364. EXTERN_API_C( double_t ) copysign(double_t x, double_t y);
  365.  
  366. EXTERN_API_C( long double ) nanl(const char *tagp);
  367.  
  368. EXTERN_API_C( double ) nan(const char *tagp);
  369.  
  370. EXTERN_API_C( float ) nanf(const char *tagp);
  371.  
  372. EXTERN_API_C( long double ) nextafterl(long double x, long double y);
  373.  
  374. EXTERN_API_C( double ) nextafterd(double x, double y);
  375.  
  376. EXTERN_API_C( float ) nextafterf(float x, float y);
  377.  
  378.  
  379.  
  380. /********************************************************************************
  381. *                                                                                 *
  382. *                              Inquiry macros                                   *
  383. *                                                                                 *
  384. *     fpclassify        Returns one of the FP_≈ values.                                *
  385. *     isnormal        Non-zero if and only if the argument x is normalized.          *
  386. *     isfinite        Non-zero if and only if the argument x is finite.             *
  387. *     isnan            Non-zero if and only if the argument x is a NaN.              *
  388. *     signbit            Non-zero if and only if the sign of the argument x is        *
  389. *                      negative.  This includes, NaNs, infinities and zeros.         *
  390. *                                                                                 *
  391. ********************************************************************************/
  392.  
  393. enum {
  394.     FP_SNAN                        = 0,                            /*      signaling NaN                         */
  395.     FP_QNAN                        = 1,                            /*      quiet NaN                             */
  396.     FP_INFINITE                    = 2,                            /*      + or - infinity                       */
  397.     FP_ZERO                        = 3,                            /*      + or - zero                           */
  398.     FP_NORMAL                    = 4,                            /*      all normal numbers                    */
  399.     FP_SUBNORMAL                = 5                                /*      denormal numbers                      */
  400. };
  401.  
  402. #define      fpclassify(x)    ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  403.                               __fpclassify  ( x ) :                            \
  404.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  405.                               __fpclassifyd ( x ) :                            \
  406.                               __fpclassifyf ( x ) )
  407. #define      isnormal(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  408.                               __isnormal ( x ) :                               \
  409.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  410.                               __isnormald ( x ) :                              \
  411.                               __isnormalf ( x ) )
  412. #define      isfinite(x)      ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  413.                               __isfinite ( x ) :                               \
  414.                                 ( sizeof ( x ) == sizeof(double) ) ?           \
  415.                               __isfinited ( x ) :                              \
  416.                               __isfinitef ( x ) )
  417. #define      isnan(x)         ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  418.                               __isnan ( x ) :                                  \
  419.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  420.                               __isnand ( x ) :                                 \
  421.                               __isnanf ( x ) )
  422. #define      signbit(x)       ( ( sizeof ( x ) == sizeof(long double) ) ?      \
  423.                               __signbit ( x ) :                                \
  424.                               ( sizeof ( x ) == sizeof(double) ) ?             \
  425.                               __signbitd ( x ) :                               \
  426.                               __signbitf ( x ) )
  427. EXTERN_API_C( long ) __fpclassify(long double x);
  428.  
  429. EXTERN_API_C( long ) __fpclassifyd(double x);
  430.  
  431. EXTERN_API_C( long ) __fpclassifyf(float x);
  432.  
  433. EXTERN_API_C( long ) __isnormal(long double x);
  434.  
  435. EXTERN_API_C( long ) __isnormald(double x);
  436.  
  437. EXTERN_API_C( long ) __isnormalf(float x);
  438.  
  439. EXTERN_API_C( long ) __isfinite(long double x);
  440.  
  441. EXTERN_API_C( long ) __isfinited(double x);
  442.  
  443. EXTERN_API_C( long ) __isfinitef(float x);
  444.  
  445. EXTERN_API_C( long ) __isnan(long double x);
  446.  
  447. EXTERN_API_C( long ) __isnand(double x);
  448.  
  449. EXTERN_API_C( long ) __isnanf(float x);
  450.  
  451. EXTERN_API_C( long ) __signbit(long double x);
  452.  
  453. EXTERN_API_C( long ) __signbitd(double x);
  454.  
  455. EXTERN_API_C( long ) __signbitf(float x);
  456.  
  457. EXTERN_API_C( double_t ) __inf(void );
  458.  
  459.  
  460.  
  461. /********************************************************************************
  462. *                                                                                 *
  463. *                      Max, Min and Positive Difference                         *
  464. *                                                                                 *
  465. *     fdim        Determines the 'positive difference' between its arguments:     *
  466. *                { x - y, if x > y }, { +0, if x <= y }.  If one argument is        *
  467. *                  NaN, then fdim returns that NaN.  if both arguments are NaNs,     *
  468. *                 then fdim returns the first argument.                            *
  469. *                                                                                 *
  470. *     fmax        Returns the maximum of the two arguments.  Corresponds to the    *
  471. *                max function in FORTRAN.  NaN arguments are treated as missing     *
  472. *                data.  If one argument is NaN and the other is a number, then     *
  473. *                the number is returned.  If both are NaNs then the first         *
  474. *                argument is returned.                                             *
  475. *                                                                                 *
  476. *     fmin        Returns the minimum of the two arguments.  Corresponds to the    *
  477. *                min function in FORTRAN.  NaN arguments are treated as missing     *
  478. *                data.  If one argument is NaN and the other is a number, then     *
  479. *                the number is returned.  If both are NaNs then the first         *
  480. *                argument is returned.                                            *
  481. *                                                                                 *
  482. ********************************************************************************/
  483. EXTERN_API_C( double_t ) fdim(double_t x, double_t y);
  484.  
  485. EXTERN_API_C( double_t ) fmax(double_t x, double_t y);
  486.  
  487. EXTERN_API_C( double_t ) fmin(double_t x, double_t y);
  488.  
  489.  
  490.  
  491. /*******************************************************************************
  492. *                                Constants                                     *
  493. *******************************************************************************/
  494. extern const double_t pi;
  495.  
  496.  
  497. /********************************************************************************
  498. *                                                                                 *
  499. *                              Non NCEG extensions                                *
  500. *                                                                                 *
  501. ********************************************************************************/
  502. #ifndef __NOEXTENSIONS__
  503. /********************************************************************************
  504. *                                                                                 *
  505. *                              Financial functions                              *
  506. *                                                                                 *
  507. *     compound        Computes the compound interest factor "(1 + rate)^periods"    *
  508. *                      more accurately than the straightforward computation with     *
  509. *                    the Power function.  This is SANE's compound function.      *
  510. *                                                                                 *
  511. *     annuity            Computes the present value factor for an annuity             *
  512. *                      "(1 - (1 + rate)^(-periods)) /rate" more accurately than    *
  513. *                    the straightforward computation with the Power function.     *
  514. *                    This is SANE's annuity function.                              *
  515. *                                                                                 *
  516. ********************************************************************************/
  517. EXTERN_API_C( double_t ) compound(double_t rate, double_t periods);
  518.  
  519. EXTERN_API_C( double_t ) annuity(double_t rate, double_t periods);
  520.  
  521.  
  522.  
  523. /********************************************************************************
  524. *                                                                                 *
  525. *                              Random function                                  *
  526. *                                                                                 *
  527. *     randomx            A pseudorandom number generator.  It uses the iteration:    *
  528. *                                (75*x)mod(2^31-1)                                *
  529. *                                                                                 *
  530. ********************************************************************************/
  531. EXTERN_API_C( double_t ) randomx(double_t *x);
  532.  
  533.  
  534.  
  535. /*******************************************************************************
  536. *                              Relational operator                             *
  537. *******************************************************************************/
  538. /*      relational operator      */
  539. typedef short                             relop;
  540.  
  541. enum {
  542.     GREATERTHAN                    = 0,
  543.     LESSTHAN                    = 1,
  544.     EQUALTO                        = 2,
  545.     UNORDERED                    = 3
  546. };
  547.  
  548. EXTERN_API_C( relop ) relation(double_t x, double_t y);
  549.  
  550.  
  551.  
  552. /********************************************************************************
  553. *                                                                                 *
  554. *                         Binary to decimal conversions                         *
  555. *                                                                                 *
  556. *     SIGDIGLEN    Significant decimal digits.                                        *
  557. *                                                                                 *
  558. *     decimal        A record which provides an intermediate unpacked form for        *
  559. *                programmers who wish to do their own parsing of numeric input     *
  560. *                or formatting of numeric output.                                  *
  561. *                                                                                 *
  562. *     decform        Controls each conversion to a decimal string.  The style field     *
  563. *                is either FLOATDECIMAL or FIXEDDECIMAL. If FLOATDECIMAL, the     *
  564. *                value of the field digits is the number of significant digits.  *
  565. *                  If FIXEDDECIMAL value of the field digits is the number of        *
  566. *                digits to the right of the decimal point.                         *
  567. *                                                                                 *
  568. *     num2dec        Converts a double_t to a decimal record    using a decform.        *
  569. *     dec2num        Converts a decimal record d to a double_t value.                *
  570. *     dec2str        Converts a decform and decimal to a string using a decform.        *
  571. *     str2dec        Converts a string to a decimal struct.                            *
  572. *     dec2d        Similar to dec2num except a double is returned (68k only).        *
  573. *     dec2f        Similar to dec2num except a float is returned.                    *
  574. *     dec2s        Similar to dec2num except a short is returned.                    *
  575. *     dec2l        Similar to dec2num except a long is returned.                     *
  576. *                                                                                 *
  577. ********************************************************************************/
  578. #if    TARGET_CPU_PPC
  579.     #define SIGDIGLEN      36              
  580. #elif TARGET_CPU_68K
  581.     #define SIGDIGLEN      20
  582. #endif
  583. #define      DECSTROUTLEN   80               /* max length for dec2str output */
  584. #define      FLOATDECIMAL   ((char)(0))
  585. #define      FIXEDDECIMAL   ((char)(1))
  586.  
  587.  
  588. struct decimal {
  589.     char                             sgn;                        /* sign 0 for +, 1 for - */
  590.     char                             unused;
  591.     short                             exp;                        /* decimal exponent */
  592.     struct {
  593.         unsigned char                     length;
  594.         unsigned char                     text[SIGDIGLEN];        /* significant digits */
  595.         unsigned char                     unused;
  596.     }                                 sig;
  597. };
  598. typedef struct decimal decimal;
  599.  
  600. struct decform {
  601.     char                             style;                        /*  FLOATDECIMAL or FIXEDDECIMAL */
  602.     char                             unused;
  603.     short                             digits;
  604. };
  605. typedef struct decform decform;
  606.  
  607. EXTERN_API_C( void ) num2dec(const decform *f, double_t x, decimal *d);
  608.  
  609. EXTERN_API_C( double_t ) dec2num(const decimal *d);
  610.  
  611. EXTERN_API_C( void ) dec2str(const decform *f, const decimal *d, char *s);
  612.  
  613. EXTERN_API_C( void ) str2dec(const char *s, short *ix, decimal *d, short *vp);
  614.  
  615. #if TARGET_CPU_68K
  616. EXTERN_API_C( double ) dec2d(const decimal *d);
  617.  
  618. #endif  /* TARGET_CPU_68K */
  619.  
  620. EXTERN_API_C( float ) dec2f(const decimal *d);
  621.  
  622. EXTERN_API_C( short ) dec2s(const decimal *d);
  623.  
  624. EXTERN_API_C( long ) dec2l(const decimal *d);
  625.  
  626.  
  627.  
  628.  
  629. /********************************************************************************
  630. *                                                                                 *
  631. *                         68k-only Transfer Function Prototypes                 *
  632. *                                                                                 *
  633. ********************************************************************************/
  634. #if TARGET_CPU_68K
  635. #if TARGET_RT_MAC_68881
  636. EXTERN_API_C( void ) x96tox80(const extended96 *x, extended80 *x80);
  637.  
  638. EXTERN_API_C( void ) x80tox96(const extended80 *x80, extended96 *x);
  639.  
  640. #else
  641. EXTERN_API_C( void ) x96tox80(const extended96 *x96, extended80 *x);
  642.  
  643. EXTERN_API_C( void ) x80tox96(const extended80 *x, extended96 *x96);
  644.  
  645. #endif  /* TARGET_RT_MAC_68881 */
  646.  
  647. #endif  /* TARGET_CPU_68K */
  648.  
  649. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  650.  
  651. /********************************************************************************
  652. *                                                                                 *
  653. *                         PowerPC-only Function Prototypes                         *
  654. *                                                                                 *
  655. ********************************************************************************/
  656.  
  657. #if TARGET_CPU_PPC
  658. EXTERN_API_C( long double ) cosl(long double x);
  659.  
  660. EXTERN_API_C( long double ) sinl(long double x);
  661.  
  662. EXTERN_API_C( long double ) tanl(long double x);
  663.  
  664. EXTERN_API_C( long double ) acosl(long double x);
  665.  
  666. EXTERN_API_C( long double ) asinl(long double x);
  667.  
  668. EXTERN_API_C( long double ) atanl(long double x);
  669.  
  670. EXTERN_API_C( long double ) atan2l(long double y, long double x);
  671.  
  672. EXTERN_API_C( long double ) coshl(long double x);
  673.  
  674. EXTERN_API_C( long double ) sinhl(long double x);
  675.  
  676. EXTERN_API_C( long double ) tanhl(long double x);
  677.  
  678. EXTERN_API_C( long double ) acoshl(long double x);
  679.  
  680. EXTERN_API_C( long double ) asinhl(long double x);
  681.  
  682. EXTERN_API_C( long double ) atanhl(long double x);
  683.  
  684. EXTERN_API_C( long double ) expl(long double x);
  685.  
  686. EXTERN_API_C( long double ) expm1l(long double x);
  687.  
  688. EXTERN_API_C( long double ) exp2l(long double x);
  689.  
  690. EXTERN_API_C( long double ) frexpl(long double x, int *exponent);
  691.  
  692. EXTERN_API_C( long double ) ldexpl(long double x, int n);
  693.  
  694. EXTERN_API_C( long double ) logl(long double x);
  695.  
  696. EXTERN_API_C( long double ) log1pl(long double x);
  697.  
  698. EXTERN_API_C( long double ) log10l(long double x);
  699.  
  700. EXTERN_API_C( long double ) log2l(long double x);
  701.  
  702. EXTERN_API_C( long double ) logbl(long double x);
  703.  
  704. EXTERN_API_C( long double ) scalbl(long double x, long n);
  705.  
  706. EXTERN_API_C( long double ) fabsl(long double x);
  707.  
  708. EXTERN_API_C( long double ) hypotl(long double x, long double y);
  709.  
  710. EXTERN_API_C( long double ) powl(long double x, long double y);
  711.  
  712. EXTERN_API_C( long double ) sqrtl(long double x);
  713.  
  714. EXTERN_API_C( long double ) erfl(long double x);
  715.  
  716. EXTERN_API_C( long double ) erfcl(long double x);
  717.  
  718. EXTERN_API_C( long double ) gammal(long double x);
  719.  
  720. EXTERN_API_C( long double ) lgammal(long double x);
  721.  
  722. EXTERN_API_C( long double ) ceill(long double x);
  723.  
  724. EXTERN_API_C( long double ) floorl(long double x);
  725.  
  726. EXTERN_API_C( long double ) rintl(long double x);
  727.  
  728. EXTERN_API_C( long double ) nearbyintl(long double x);
  729.  
  730. EXTERN_API_C( long ) rinttoll(long double x);
  731.  
  732. EXTERN_API_C( long double ) roundl(long double x);
  733.  
  734. EXTERN_API_C( long ) roundtoll(long double round);
  735.  
  736. EXTERN_API_C( long double ) truncl(long double x);
  737.  
  738. EXTERN_API_C( long double ) remainderl(long double x, long double y);
  739.  
  740. EXTERN_API_C( long double ) remquol(long double x, long double y, int *quo);
  741.  
  742. EXTERN_API_C( long double ) copysignl(long double x, long double y);
  743.  
  744. EXTERN_API_C( long double ) fdiml(long double x, long double y);
  745.  
  746. EXTERN_API_C( long double ) fmaxl(long double x, long double y);
  747.  
  748. EXTERN_API_C( long double ) fminl(long double x, long double y);
  749.  
  750.  
  751. #ifndef __NOEXTENSIONS__
  752. EXTERN_API_C( relop ) relationl(long double x, long double y);
  753.  
  754. EXTERN_API_C( void ) num2decl(const decform *f, long double x, decimal *d);
  755.  
  756. EXTERN_API_C( long double ) dec2numl(const decimal *d);
  757.  
  758. /*    
  759.     MathLib v2 has two new transfer functions: x80tod and dtox80.  They can 
  760.     be used to directly transform 68k 80-bit extended data types to double
  761.     and back for PowerPC based machines without using the functions
  762.     x80told or ldtox80.  Double rounding may occur. 
  763. */
  764. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  765.  
  766. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  767.  
  768. EXTERN_API_C( double ) x80tod(const extended80 *x80);
  769.  
  770. EXTERN_API_C( void ) dtox80(const double *x, extended80 *x80);
  771.  
  772. #endif  /*  ! defined(__NOEXTENSIONS__)  */
  773.  
  774. #endif  /* TARGET_CPU_PPC */
  775.  
  776. #else
  777. /*
  778.     Non-Mac platforms may have long doubles.
  779. */
  780. EXTERN_API_C( void ) x80told(const extended80 *x80, long double *x);
  781.  
  782. EXTERN_API_C( void ) ldtox80(const long double *x, extended80 *x80);
  783.  
  784. #endif  /* TARGET_OS_MAC */
  785.  
  786.  
  787. #if PRAGMA_STRUCT_ALIGN
  788.     #pragma options align=reset
  789. #elif PRAGMA_STRUCT_PACKPUSH
  790.     #pragma pack(pop)
  791. #elif PRAGMA_STRUCT_PACK
  792.     #pragma pack()
  793. #endif
  794.  
  795. #ifdef PRAGMA_IMPORT_OFF
  796. #pragma import off
  797. #elif PRAGMA_IMPORT
  798. #pragma import reset
  799. #endif
  800.  
  801. #ifdef __cplusplus
  802. }
  803. #endif
  804.  
  805. #endif /* __FP__ */
  806.  
  807.